<template>
    <div class="root">
        <timers></timers>
        <div class="container">
            <h1>手机号登录</h1>
            <div class="linecontainer noline">
                <div class="type">国家</div>
                <div class="input">
                    <input type="text" class="sex" disabled placeholder="中国大陆+(86)">
                </div>
            </div>
            <div class="linecontainer">
                <div class="type">手机号</div>
                <div class="input">
                    <input type="text" v-model="userMsg.phone" placeholder="请填写手机号">
                </div>
            </div>
            <div class="linecontainer">
                <div class="type">密码</div>
                <div class="input">
                    <input type="password" v-model="userMsg.password" placeholder="请填写密码">
                </div>
            </div>
            <div class="linecontainer noline">
                <div class="types" @click="others">使用微信号/QQ号/邮箱登录</div>
            </div>
            <transition name="btns">
                <div class="iconcontainer" v-if="btnflag">
                    <span class="fa fa-qq fa-lg"></span>
                    <span class="fa fa-weixin fa-lg"></span>
                    <span class="fa fa-envelope-open-o fa-lg"></span>
                </div>
            </transition>
            <button ref="login" @click="tologin" :disabled="btnuse">登录</button>
        </div>
        <span class="fa fa-chevron-left btn" @click="tofirst" ref="btn"></span>
    </div>
</template>

<script>
export default {
    data(){
        return {
            btnflag:false,
            btnuse:false,
            userMsg:{
                phone:'',
                password:''
            }
        }
    },
    methods:{
        async tologin(){
            console.log('star')
            // this.$router.push('/home')
            const {data} = await this.$http.post('/api/userLogin',this.userMsg)
            if(data.msg==='success'){
                console.log(data)
                window.sessionStorage.setItem('token',data.tokenId)  //写入sessionsttorage中
                window.sessionStorage.setItem('userMsg',data.userMsg)
                this.$router.push('/home')  //跳转到登陆后的界面
            }else{
                alert('账号或密码错误')
            }
        },
        btnshow(){
            if(this.userMsg.phone!==''&&this.userMsg.password!==''){
                this.$refs.login.classList.add('butstyle')
                this.btnuse = false
                
            }else{
                this.$refs.login.classList.remove('butstyle')
                this.btnuse = !this.btnuse
                this.btnuse = true
            }
        },
        others(){
            this.btnflag = !this.btnflag
        },
        tofirst(){
            this.$router.push('/')
        }
    },
    watch:{
        'userMsg.phone':function(newmsg, oldmsg){
            if(newmsg !==''||newmsg!==undefined){
                this.btnshow()
            }
        },
        'userMsg.password':function(newmsg, oldmsg){
            if(newmsg !==''||newmsg!==undefined){
                this.btnshow()
            }
        }
    },
    sockets:{
        ids(value){
            window.sessionStorage.setItem('socketid',value)
        }
    }
}
</script>

<style lang="less" scoped>
    .root{
        width: 100vw;
        height: 100vh;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
    }
    .container{
        width: 95vw;
        height: 100%;
        // border: 1px solid #ccc;
    }
    h1{
        font-weight: normal;
        margin: 50px 0 50px 20px;
    }
    .linecontainer{
        width: 100%;
        height: 55px;
        // background-color: skyblue;
        border-bottom: 1px solid #bbb;
        display: flex;
        .type{
            width: 80px;
            height: 55px;
            // background-color: #bfa;
            display: flex;
            // justify-content: center;
            // margin-left: 10px;
            padding-left: 15px;
            align-items: center;
        }
        .types{
            display: flex;
            width: 100%;
            height: 55px;
            margin-left: 15px;
            align-items: center;
            font-size: 15px;
            color: rgb(26, 26, 166);
        }
        .input{
            height: 55px;
            flex-grow: 1;
            // background-color: #2ecc71;
            input{
                width: 100%;
                height: 100%;
                border: none;
                background: none;
                outline: none;
            }
        }
    }
    .iconcontainer{
        width: 100%;
        height: 40px;
        // background-color: #2ecc71;
        display: flex;
        justify-content: center;
        align-items: center;
        transition: .5s all ease-in-out;
        // display: none;
        span:nth-child(2){
            margin: 0 25px;
        }
    }
    button{
        width: 100%;
        height: 50px;
        background-color: rgb(226, 226, 226);
        border: none;
        outline: none;
        border-radius: 5px;
        color: rgb(184, 184, 184);
        font-size: 20px;
    }
    .sex::-webkit-input-placeholder{
        color: rgb(30, 184, 104);
    }
    .noline{
        border-bottom: none;
    }
    .btn{
        position: absolute;
        top: 15px;
        left: 10px;
    }
    .butstyle{
        background-color:rgb(12, 203, 25);
        color: white;
    }
    // 动画
    .btns-enter,
    .btns-leave-to{
        opacity: 0;
    }
    .btn-enter-active,
    .btn-leave-active{
        transition: .5s all ease-in-out;
    }
</style>
